home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * MacZoop - "the framework for the rest of us"
- *
- *
- *
- * ZFileStream.cpp -- a stream using file storage
- *
- *
- *
- *
- *
- * © 1998, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
-
- #include "ZFileStream.h"
- #include "ZErrors.h"
-
-
- /*--------------------------------*** CONSTRUCTOR ***---------------------------------*/
-
- ZFileStream::ZFileStream( const FSSpec& aFileSpec )
- : ZFile( aFileSpec ), ZStream()
- {
- classID = CLASS_ZFileStream;
-
- InitFileStream();
- }
-
- /*--------------------------------*** CONSTRUCTOR ***---------------------------------*/
-
- ZFileStream::ZFileStream( Str255 fName )
- : ZFile( fName ), ZStream()
- {
- classID = CLASS_ZFileStream;
-
- InitFileStream();
- }
-
- /*--------------------------------*** CONSTRUCTOR ***---------------------------------*/
-
- ZFileStream::ZFileStream()
- : ZFile(), ZStream()
- {
- classID = CLASS_ZFileStream;
- }
-
-
- /*---------------------------------*** DESTRUCTOR ***---------------------------------*/
-
- ZFileStream::~ZFileStream()
- {
- if ( dataWasWritten )
- SetLength( GetMark());
- }
-
-
- /*------------------------------------*** RESET ***-----------------------------------*/
- /*
- reset the stream in order to re-read it from the beginning (use VERY carefully!)
- ----------------------------------------------------------------------------------------*/
-
- void ZFileStream::Reset()
- {
- SetMark( 0 );
- }
-
-
- /*------------------------------------*** SKIP ***------------------------------------*/
- /*
- move stream mark without reading or writing data
- ----------------------------------------------------------------------------------------*/
-
- void ZFileStream::Skip( long bytesToSkip )
- {
- FailOSErr( SetFPos( refNum, fsFromMark, bytesToSkip ));
- }
-
-
- /*-----------------------------------*** PUTTO ***------------------------------------*/
- /*
- write data to stream storage (file)
- ----------------------------------------------------------------------------------------*/
-
- void ZFileStream::PutTo( void* data, long dataLen )
- {
- Write((Ptr) data, &dataLen );
-
- dataWasWritten = TRUE;
- }
-
-
- /*-----------------------------------*** GETFROM ***----------------------------------*/
- /*
- read data from stream storage (file)
- ----------------------------------------------------------------------------------------*/
-
- void ZFileStream::GetFrom( void* data, long* dataLen )
- {
- Read((Ptr) data, dataLen );
- }
-
- /*-------------------------------*** INITFILESTREAM ***-------------------------------*/
- /*
- common initialiser opens the file ready to read or write.
- ----------------------------------------------------------------------------------------*/
-
- void ZFileStream::InitFileStream()
- {
- if ( ! IsReal())
- Create();
-
- Open();
-
- dataWasWritten = FALSE;
- }
-